import request from '@/utils/request'
import type { ApiResponse } from '@/types'

export interface UploadResponse {
  url: string
}

export const uploadApi = {
  // 上传图片 - POST /upload
  uploadFile: (file: File): Promise<ApiResponse<string>> => {
    const formData = new FormData()
    formData.append('image', file)  // 根据用户反馈，参数名为image
    
    return request({
      method: 'POST',
      url: '/upload',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },
  
  // 兼容旧方法名
  uploadImage: (file: File): Promise<ApiResponse<string>> => {
    return uploadApi.uploadFile(file)
  }
}